﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace M3G {
    public class Appearance : AppearanceBase {

        #region Field
        private Material        material;
        private Fog             fog;
        private PointSpriteMode pointSpriteMode;
        private Texture2D[]     textures;
        #endregion


        #region Method
        public Appearance () {
            this.material = null;
            this.fog = null;
            this.pointSpriteMode = null;
            this.textures = new Texture2D[2] { null, null };
        }

        protected Appearance (Appearance appearance)
            : base (appearance) {
            this.material = appearance.material;
            this.pointSpriteMode = appearance.pointSpriteMode;
            this.fog = appearance.fog;
            this.textures = (Texture2D[])appearance.textures.Clone ();
        }

        public Fog Fog {
            get { return fog; }
        }

        public void SetFog (Fog fog) {
            this.fog = fog;
        }

        public Material Material {
            get { return material; }
        }

        public void SetMaterial (Material material) {
            this.material = material;
        }

        public PointSpriteMode PointSpriteMode {
            get { return pointSpriteMode; }
        }

        public void SetPointSpriteMode (PointSpriteMode pointSpriteMode) {
            this.pointSpriteMode = pointSpriteMode;
        }

        public Texture2D[] Texture {
            get { return (Texture2D[])textures.Clone (); }
        }

        public void SetTexture (int index, Texture2D texture) {
            if (index < 0 || index > 1) {
                throw new ArgumentOutOfRangeException ("Index must be within [0,1], index=" + index);
            }

            this.textures[index] = texture;
        }

        public override Object3D[] References {
            get {
                var q = new List<Object3D> ();
                q.AddRange (base.References);
                q.Add (material);
                q.Add (fog);
                q.Add (pointSpriteMode);
                q.AddRange (textures);
                q.RemoveAll (x => x == null);
                return q.ToArray ();
            }
        }

        public override Object3D Duplicate () {
            return new Appearance (this);
        }

        #endregion
    }
}
